{include file="public/header" /}
<body class="gray-bg">
<div class="wrapper wrapper-content">
    <div class="ibox float-e-margins">
        <div class="ibox-content">
            <div class="row">
                <!--搜索框开始-->
                <div class="col-sm-12">
                    <div class="layui-form layui-form-item">
                        <div class="layui-col-md6 layui-input-inline">
                            <select name="lunbo_status" lay-search="" class="layui-input">
                                <option  value="">全部状态</option>
                                <option  value="1">启用</option>
                                <option  value="2">禁用</option>
                            </select>
                        </div>
                        <div class="layui-col-md6 layui-input-inline">
                            <select name="lunbo_type" lay-search="" class="layui-input">
                                <option  value="">全部类别</option>
                                <option  value="1">首页</option>
                                <option  value="2">任务</option>
                                <option  value="3">全部</option>
                            </select>
                        </div>
                        <!--<div class="layui-col-md6 layui-input-inline">-->
                            <!--<input type="text" id="key" class="layui-input search" name="key" value="" placeholder="用户手机号码|用户名称"/>-->
                        <!--</div>-->
                        <div class="layui-input-inline">
                            <button class="layui-btn" lay-submit="" lay-filter="LAY-search">立即搜索</button>
                            <button  class="layui-btn layui-btn-normal" id="empty"  lay-submit="" lay-filter="LAY-search">重置</button>
                        </div>
                    </div>
                </div>
                <div class="col-sm-12">
                    <div class="input-group" >
                        <button class="btn btn-primary" type="button" onclick="wk.href('{:url('add')}');">
                            <i class="fa fa-plus"></i> 添加轮播图
                        </button>
                    </div>
                </div>
                <!--搜索框结束-->
            </div>
            <div class="hr-line-dashed"></div>

            <div class="example-wrap">
                <div class="example">
                    <table class="layui-hide" id="test" lay-filter="testReload"></table>
                    <script type="text/html" id="lunbo_image">
                      <img src="{{d.lunbo_image}}" class="layui-table-img layui-cricle" onerror="this.src='/static/admin/images/head_default.gif'"/>
                    </script>
                    <script type="text/html" id="lunbo_type">
                        {{# if(d.lunbo_type ==1){ }}
                        首页
                        {{# } }}
                        {{# if(d.lunbo_type ==2){ }}
                        任务
                        {{# } }}
                        {{# if(d.lunbo_type ==3){ }}
                        全部
                        {{# } }}
                    </script>
                    <script type="text/html" id="lunbo_status">
                        {{# if(d.lunbo_status ==1){ }}
                        启用
                        {{# } }}
                        {{# if(d.lunbo_status ==2){ }}
                        禁用
                        {{# } }}
                    </script>
                    <!--操作模板-->
                    <script type="text/html" id="opeBar">
                        {{# if(d.lunbo_status ==2){ }}
                        <!--<a href="javascript:;" onclick="wk.href('{:url('money')}?id={{d.apply_id}}')" class="btn btn-primary btn-xs m-r-xs">启用</a>-->
                        <a href="javascript:;" onclick="wk.confirm('{{d.lunbo_id}}','{:url('enable')}','确定要启用吗?')" class="btn btn-success btn-xs m-r-xs">启用</a>
                        {{# } }}
                        {{# if(d.lunbo_status ==1){ }}
                        <a href="javascript:;" onclick="wk.confirm('{{d.lunbo_id}}','{:url('prohibit')}','确定要禁用吗?')" class="btn btn-warning btn-xs m-r-xs">禁用</a>
                        {{# } }}
                        <!--<a href="javascript:;" onclick="wk.confirm('{{d.revenue_id}}','{:url('excelIn')}','确定要隐藏轮播图吗?')" class="btn btn-warning btn-xs m-r-xs" title="隐藏"><i class="fa fa-toggle-off"></i></a>-->
                        <a href="javascript:;" onclick="wk.href('{:url('update')}?id={{d.lunbo_id}}')" class="btn btn-primary btn-xs m-r-xs">编辑</a>
                        <a href="javascript:;" onclick="wk.href('{:url('detail')}?id={{d.lunbo_id}}')" class="btn btn-primary btn-xs m-r-xs">查看</a>

                    </script>
                </div>
            </div>
        </div>
    </div>
</div>
{include file="public/footer" /}
<script>
    //layui渲染数据表格
    layui.use('table', function () {
        var table = layui.table
                , form = layui.form;
        table.render({
            elem: '#test'
            , url: '{:url("banner/index")}'
            ,response: {
                statusCode: 220 //成功的状态码，默认：0
            }
            , page: true
            , size: 'lg' //sm小尺寸的表格 lg大尺寸
            , cellMinWidth: 150
            , limits: [5, 10, 15, 20, 25, 30]
            , limit: "{:config('pages')}"
            , loading: true
            , id: 'testReload'
            , cols: [[
//                {type: 'checkbox', fixed: 'left',}
                  {type:'numbers', width: 70, title: '序号'}
                , {field: 'lunbo_name', width: 200, title: '名称', align: 'center'}
                , {field: 'lunbo_type', width: 100, title: '类别', align: 'center',templet:"#lunbo_type"}
                , {field: 'lunbo_image', width: 200, title: '轮播缩略图', align: 'center',templet:"#lunbo_image"}
                , {field: 'task_name', width: 150, title: '链接地址', align: 'center'}
                , {field: 'lunbo_update_time', width: 200, title: '编辑时间', align: 'center'}
                , {field: 'lunbo_status', width: 200, title: '状态', align: 'center',templet:"#lunbo_status"}
                , {field: 'lunbo_px', width: 200, title: '排序', align: 'center',edit: 'text'}
                , {fixed: 'right', width:200, title: '操作', align: 'center', toolbar: '#opeBar'}
            ]]
            ,done: function (res, curr, count) {
                $('.layui-cricle').viewer();//图片查看器
            }
        });
        //监听状态开关操作
        form.on('switch(OnOff)', function (obj) {
            var num = '';
            obj.elem.checked == true? num = 1: num = 2;
            //用户状态
            wk.status(this.value,num, '{:url("memberState")}',obj);
        });
        //监听单元格编辑
        table.on('edit(testReload)', function(obj){
            var value = obj.value //得到修改后的值
                    ,data = obj.data //得到所在行所有键值
                    ,field = obj.field; //得到字段
            // layer.msg('[ID: '+ data.id +'] ' + field + ' 字段更改为：'+ value);

                var patrn = /^[0-9]*$/;
                if(!patrn.test(value)){
                    layer.msg('排序值只能为数字',{icon:2,time:1500,shade: 0.1},function(){
                        //重载当前页表格
                        $(".layui-laypage-btn").click();
                    });
                    return false;
                }
                wk.change(data.lunbo_id,"{:url('edit')}",field,value);
        });
        //批量操作
        var $ = layui.$, active = {
            usingAllS: function(){
                //导出Excel
                wk.money(getIds(),"{:url('money')}");
            }
        };
        $('.layuiBtn').on('click', function () {
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });
        var getIds = function () {
            var ids = [];
            var checkStatus = table.checkStatus('testReload')
                    ,data = checkStatus.data;
            $.each(data,function(index,item){
                ids.push(item['apply_id'])
            });
            return ids;
        }
    });
</script>
</body>
</html>